using System;
using System.Data;

namespace Dbam.DbFramework
{
	/// <summary>
	/// Enumeration for sort directions.
	/// </summary>
	public enum SortDirection
	{
		Ascending,
		Descending
	}

	/// <summary>
	/// Attribute for a property of an entity that can be sorted.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
	public class SortableColumnAttribute
		: ColumnAttribute
	{
		#region Data Members

		/// <summary>
		/// The direction of the sort (ascending or descending).
		/// </summary>
		private SortDirection _direction;

		/// <summary>
		/// Ordinal of the sort. Should be non-negative value.
		/// </summary>
		private int _ordinal;

		#endregion

		#region Constructor(s)

		/// <summary>
		/// Initialize the sort information.
		/// </summary>
		/// <param name="columnName">Name of the mapped column.</param>
		/// <param name="type">Data type of the mapped column.</param>
		/// <param name="isPrimaryKey">Flag indicating whether the column is a primary key column.</param>
		/// <param name="direction">Direction of the sort.</param>
		/// <param name="ordinal">Ordinal of the sort.</param>
		public SortableColumnAttribute(string columnName, DbType dbType, bool isPrimaryKey, SortDirection direction, int ordinal)
			: base(columnName, dbType, isPrimaryKey)
		{
			_direction = direction;
			_ordinal = ordinal;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Gets the direction of the sort.
		/// </summary>
		public SortDirection Direction
		{
			get { return _direction; }
		}

		/// <summary>
		/// Gets the ordinal position for the sort.
		/// </summary>
		public int Ordinal
		{
			get { return _ordinal; }
		}

		#endregion
	}
}